﻿function UserLogin(loginData) {
    $.ajax({
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        url: "/Api/LoginApi/UserLogin",
        data: JSON.stringify(loginData),
        success: function (data, textStatus, jqXHR) {
            if (data.Success) {
                let returnUrl = GetUrlParameter("ReturnUrl");
                if (returnUrl) {
                    location.assign(returnUrl);
                } else {
                    location.assign("/Index.aspx");
                }
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log(errorThrown);
        }
    });
}

function GetUrlParameter(name) {
    const regex = new RegExp("[?&]" + name + "=([^&#]+)", "i");
    const match = location.search.match(regex);  //匹配目标参数
    if (match) {
        return decodeURIComponent(match[1]);
    } else {
        return null;
    }
}